<?php
/**
 * Created by PhpStorm
 * USER:  Zhaoys
 * Date:  2024/3/11
 */
// map a route
//$router->get('/', function ($request) {
//    $response = new Laminas\Diactoros\Response;
//    $response->getBody()->write('<h1>Hello, World!</h1>');
//    return $response;
//});
//$router->get('/home', function ($request) {
//    $response = new Laminas\Diactoros\Response;
//    $response->getBody()->write('<h1>Hello, Home Page!</h1>');
//    return $response;
//});
//
//
//$router->get('/abc', function ($request) {
//    return response('hello world');
//});
//$router->get('/123', function ($request) {
//
//    return response('hello home page');
//});
//
//$router->get('/ab', function ($request) {
//
//    $view_path = __DIR__ . '/../resources/views';
//
//    $loader = new \Twig\Loader\FilesystemLoader($view_path);
//
//    $twig = new \Twig\Environment($loader, [
//        'cache' => false,
//    ]);
//
//    $content = $twig->render('index.twig', ['name' => 'Caoayu']);
//    return response($content);
//});


//$router->get('/', function ($request)  {
//    $name = 'caoayu';
//    return view('index.twig',compact('name'));
//});

$router->get('/', function ($request) {

    $view_path = __DIR__ . '/../resources/views';

    $loader = new \Twig\Loader\FilesystemLoader($view_path);

    $twig = new \Twig\Environment($loader, [
        'cache' => __DIR__ . '/../storage/views',
    ]);
    $content = $twig->render('index.twig', ['name' => 'Caoayu']);
    return response($content);
});